import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Executors;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpServer;

public class BenchJdk {
	private static final int PORT = Integer.getInteger("port", 10000);
	private static final byte[] body = "Hello, World!".getBytes(StandardCharsets.UTF_8);

	public static void main(String[] args) throws IOException {
		HttpServer hs = HttpServer.create(new InetSocketAddress(PORT), 1024 * 8);
		hs.setExecutor(Executors.newFixedThreadPool(Integer.getInteger("thread", 1)));
		hs.createContext("/plaintext", he -> {
			Headers h = he.getResponseHeaders();
			h.add("Server", "jdkhs");
			h.add("Content-Type", "text/plain; charset=UTF-8");
			he.sendResponseHeaders(200, body.length);
			try (OutputStream os = he.getResponseBody()) {
				os.write(body);
			}
		});
		hs.start();
	}
}
